<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>用户管理-WeAdmin Frame型后台管理系统-WeAdmin 1.0</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, customer-scalable=0">
<link rel="stylesheet" href="../../static/css/font.css">
<link rel="stylesheet" href="../../static/css/weadmin.css">
<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
<!--[if lt IE 9]>
	      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
	      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
	    <![endif]-->
</head>

<body>
	<div class="weadmin-body">
		<div class="weadmin-block">
			<div style="margin-left: 30px;" class="layui-inline">
				<input type="text" id="staff_search_keyword" name="keyword"
					placeholder="姓名/职位" autocomplete="off" class="layui-input">
			</div>
			<button class="layui-btn" onclick="staffSearch()" lay-filter="sreach">
				<i class="layui-icon">&#xe615;</i>
			</button>
			<span class="fr" style="line-height: 40px"></span>
		</div>
		<!--  用户表格 -->
		<table class="layui-table" lay-filter="staff_table" id="staff_table" style="margin: 0"></table>
	</div>
	<script src="../../lib/layui/layui.js" charset="utf-8"></script>
	<script src="../../static/js/admin.js" charset="utf-8"></script>
	<script src="../../publicjs/jquery-1.8.0.min.js" charset="utf-8"></script>
	<script src="../../publicjs/smallkingutil.js" charset="utf-8"></script>
	<script>
		layui.use('table', function() {
			var table = layui.table;
			// 加载用户数据表格
			window.staffTable = table.render({
				id : 'staffTable',
				elem : '#staff_table',
				url : commonUtil.domain() +'/admin/wxwork/staff/list', //数据接口
				method : 'post',
				page : true, //开启分页
				request : {
					pageName : 'pageNum', // 分页当前页数发给后台的参数名
					limitName : 'pageSize', // 分页每页多少条发给后台的参数名
					countName : 'total'
				},
				done : function(res) {
					$('.layui-laypage-count').text('共' + res.total + '条')
				},
				cols : [ [ //表头
				{
					field : 'name',
					title : '姓名',
					width : 80
				}, {
					field : 'staffCode',
					title : '员工号',
					width : 120
				}, {
					field : 'position',
					title : '职位',
					width : 180
				}, {
					field : 'shortName',
					title : '所属门店',
					width : 120
				}, {
					field : 'gender',
					title : '性别',
					width : 60,
					templet : '#gender'
				}, {
					field : 'status',
					title : '状态',
					width : 90,
					templet : '#status'
				}, {
					field : 'oper',
					title : '转交',
					width : 60,
					templet : '#oper'
				} ] ]
			});
			// 刷新表格
			staffTable.refresh = function(data) {
				staffTable.reload({
					where : data,
					page : {
						curr : 1
					// 重新从第 1 页开始
					}
				});
			}
			// 搜索按钮
			window.staffSearch = function(res) {
				var keyword = $("#staff_search_keyword").val();
				// 传入关键词 重载表格
				staffTable.refresh({
					keyword : keyword
				});
			}
			var externalId = commonUtil.getRequestParam("externalId");
			var externalName = commonUtil.getRequestParam("externalName");
			// 监听表格点击删除和修改按钮
			table.on('tool(staff_table)', function(obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
				var data = obj.data; // 获得当前行数据
				var staffId = data.staffId;
				var name = data.name;
				var layEvent = obj.event; // 获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
				var tr = obj.tr; // 获得当前行 tr 的DOM对象
				if (layEvent === 'confirm') {
					layer.confirm('确定要将"' + externalName + '"转交给员工"' + name + '"吗？',function(){
						var ajaxParam = {
								url : commonUtil.domain() +'/admin/wxwork/customer/transfer',
								data : {
									staffId : staffId,
									externalId : externalId
								}
							}
						ajaxUtil.post(ajaxParam, function(data) {
							if (data.code == 200) {
								layer.alert("转交成功", {
									icon : 6
								}, function() {
									// 刷新父级的用户表格
									var parentHtml = window.parent;
									parentHtml.customerTable.refresh();
									//关闭当前frame
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
								});
							} else {
								layer.alert(data.msg);
							}
						});
					});
				}
			});
		});
	</script>
	<script>
		$(function(){
			commonUtil.setMaxLength(40);
		})
	</script>
	<script type="text/html" id="gender">
		 {{#  if(d.gender == 1){  }}
			<i style="color:#1296db" class="layui-icon">&#xe662;</i>
  		 {{#  } else { }}
			<i style="color:#FF9E9E" class="layui-icon">&#xe661;</i>
  		 {{#  } }}
	</script>
	<script type="text/html" id="oper">
		  <a lay-event="confirm" style="color:green"><i class="layui-icon">&#xe605;</i></a>
	</script>
	<script type="text/html" id="status">
		{{#  if(d.status == 1){ }}
		<span class="layui-btn layui-btn-normal layui-btn-xs">在职</span>
  		{{#  } else if(d.status == 2){ }}
		<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">禁用</span>
  		{{#  } else if(d.status == 3){ }}
		<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">离职</span>
		{{#  } else if(d.status == 4){ }}
		<span class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled">未激活</span>
  		{{#  } }}
	</script>
</body>

</html>